package com.hundsun.yr.universal.p2p.ui.activity;

import android.os.Bundle;
import android.view.View;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils;
import com.hundsun.yr.universal.library.view.BrowserLayout;
import com.hundsun.yr.universal.p2p.bean.UpdatePayPwdBeen;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;
import com.hundsun.yr.universal.p2p.utils.Logs;

import org.apache.http.util.EncodingUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

/**
 * Created by xx on 2017/5/31.
 * 展示修改交易码结果页面
 */
public class UpdatePayPwdResultActivity extends BaseActivity {
    private BrowserLayout bl_browserLayout;
    private UpdatePayPwdBeen mUpdatePayPwdBeen = null;
    private String url;
    private String zwgt_data;

    @Override
    protected boolean isApplyKitKatTranslucency() {
        return false;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.act_update_pay_pwd_result;
    }

    @Override
    protected void initViewsAndEvents() {
        // TODO: 2017/6/1 不知道如何处理
        mToolbar.setTitle("设置交易密码");
        bl_browserLayout = findView(R.id.bl_browserLayout);

        url = mUpdatePayPwdBeen.url;
        String postData = null;
        try {
            postData = "accountId=" + URLEncoder.encode(mUpdatePayPwdBeen.data.accountId.toString(), "utf-8") + "&acqRes=" + URLEncoder.encode(mUpdatePayPwdBeen.data.acqRes.toString(),"utf-8") + "&bankCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.bankCode.toString(),"utf-8")
                    + "&channel=" + URLEncoder.encode(mUpdatePayPwdBeen.data.channel.toString(), "utf-8") + "&idNo=" + URLEncoder.encode(mUpdatePayPwdBeen.data.idNo.toString(),"utf-8") + "&idType=" + URLEncoder.encode(mUpdatePayPwdBeen.data.idType.toString(),"utf-8") + "&instCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.instCode.toString(),"utf-8") + "&lastSrvAuthCode="
                    + URLEncoder.encode(mUpdatePayPwdBeen.data.lastSrvAuthCode.toString(),"utf-8") + "&mobile=" + URLEncoder.encode(mUpdatePayPwdBeen.data.mobile.toString(),"utf-8") + "&name=" + URLEncoder.encode(mUpdatePayPwdBeen.data.name.toString(),"utf-8") + "&notifyUrl=" + URLEncoder.encode(mUpdatePayPwdBeen.data.notifyUrl.toString(),"utf-8")
                    +"&retUrl=" + URLEncoder.encode(mUpdatePayPwdBeen.data.retUrl.toString(),"utf-8") + "&seqNo=" + URLEncoder.encode(mUpdatePayPwdBeen.data.seqNo.toString(),"utf-8") + "&sign=" + URLEncoder.encode(mUpdatePayPwdBeen.data.sign.toString(),"utf-8") + "&smsCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.smsCode.toString(),"utf-8")
                    + "&txCode=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txCode.toString(),"utf-8") + "&txDate=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txDate.toString(),"utf-8") + "&txTime=" + URLEncoder.encode(mUpdatePayPwdBeen.data.txTime.toString(),"utf-8") + "&version=" + URLEncoder.encode(mUpdatePayPwdBeen.data.version.toString(),"utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        Logs.e("url: " + url + ",postData: " + postData);

        bl_browserLayout.mWebView.postUrl(url, EncodingUtils.getBytes(postData, "BASE64"));


        //------------------尝试通过volley 进行网络请求
/*        url = mUpdatePayPwdBeen.url;
        VolleyRequest volleyRequest = new VolleyRequest();
        HashMap<String,String> hashMap = new HashMap<>();
        hashMap.put("accountId",mUpdatePayPwdBeen.data.accountId);
        hashMap.put("acqRes",mUpdatePayPwdBeen.data.acqRes);
        hashMap.put("bankCode",mUpdatePayPwdBeen.data.bankCode);
        hashMap.put("channel",mUpdatePayPwdBeen.data.channel);
        hashMap.put("idNo",mUpdatePayPwdBeen.data.idNo);
        hashMap.put("idType",mUpdatePayPwdBeen.data.idType);
        hashMap.put("instCode",mUpdatePayPwdBeen.data.instCode);
        hashMap.put("lastSrvAuthCode",mUpdatePayPwdBeen.data.lastSrvAuthCode);
        hashMap.put("mobile",mUpdatePayPwdBeen.data.mobile);
        hashMap.put("name",mUpdatePayPwdBeen.data.name);
        hashMap.put("notifyUrl",mUpdatePayPwdBeen.data.notifyUrl);
        hashMap.put("retUrl",mUpdatePayPwdBeen.data.retUrl);
        hashMap.put("seqNo",mUpdatePayPwdBeen.data.seqNo);
        hashMap.put("sign",mUpdatePayPwdBeen.data.sign);
        hashMap.put("smsCode",mUpdatePayPwdBeen.data.smsCode);
        hashMap.put("txCode",mUpdatePayPwdBeen.data.txCode);
        hashMap.put("txDate",mUpdatePayPwdBeen.data.txDate);
        hashMap.put("txTime",mUpdatePayPwdBeen.data.txTime);
        hashMap.put("version",mUpdatePayPwdBeen.data.version);
        volleyRequest.StringRequestPost("a", url, Constants.EVENT_DATA, hashMap, new BaseMultiLoadedListener<String>() {
            @Override
            public void onSuccess(String task_name, int event_tag, String data) throws Exception {
                //成功

            }

            @Override
            public void onException(String task_name, String msg) {
                //失败

            }
        });*/

    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        mUpdatePayPwdBeen = (UpdatePayPwdBeen) extras.getSerializable("updatepaypwdbeen");
    }

    @Override
    protected void onEveComming(EventCenter eventCenter) {

    }

    @Override
    protected boolean isBindEventBusHere() {
        return false;
    }

    @Override
    protected View getLoadingTargetView() {
        return null;
    }

    @Override
    protected void onNetworkConnected(NetUtils.NetType type) {

    }

    @Override
    protected void onNetworkDisConnected() {

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        return false;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        return null;
    }
}
